/*
 * launcher_robot5.cpp
 *
 */

#include "../middleware/CommunicationDespacho.h"
#include "../middleware/CommunicationRobot16.h"
#include "../middleware/CommunicationAdpt.h"
#include "../channel_common/AgentIdManager.h"
#include "../channel_common/ChannelInterface.h"
#include "../IPC/ProcessAux.h"
#include "../common/Argv.h"
#include "../capa_servicios_distribuidos/QueueLauncher.h"
#include "../middleware/CommunicationVendedor.h"
#include "../control/clienteCommon.h"
#include "../application/AdminKeys.h"
#include "../middleware/CommunicationRobot11.h"
#include "../middleware/CommunicationADP.h"
#include "../middleware/CommunicationPrimerCinta.h"
#include "../middleware/CommunicationRobot5.h"

using namespace middleware;

int main(int argc, char**argv)
{
	CLogger::create("Terminator del robot5");
	std::string hostName = "robot5_pc";

	Argv args;
	args.pushArg(hostName);

	channel::ChannelInterface::disconnectChannel(hostName);
	channel::ChannelInterface::destroy(hostName);

	AdminKeys adminZonaIzq(ZONA_IZQ);
	AdminKeys adminZonaMedio(ZONA_MED);
	AdminKeys adminZonaDer(ZONA_DER);

	CLogger::log("Destruyendo robot 11");
	try {
		CommunicationRobot11::destroy(adminZonaIzq.getRobot11Key());
		CommunicationRobot11::destroy(adminZonaDer.getRobot11Key());
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

//	CLogger::log("Destruyendo ADP");
//	try {
//		CommunicationADP::destroy(CommunicationADP::ROBOT5, hostName);
//	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Destruyendo cintas");
	try {
		CommunicationPrimerCinta::destroy(adminZonaIzq.getCintaKey());
		CommunicationPrimerCinta::destroy(adminZonaDer.getCintaKey());
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Destruyendo robot 5");
	try {
		CommunicationRobot5::destroy(CommunicationRobot5::R5, hostName);
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}
}
